package uk.co.jonlt.AndBus;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class StopAdapter extends BaseAdapter implements OnClickListener {
    private Context context;

    private List<Stop> listStop;

    public StopAdapter(Context context, List<Stop> listStop) {
        this.context = context;
        this.listStop = listStop;
    }

	public int getCount() {
        return listStop.size();
    }

    public Object getItem(int position) {
        return listStop.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup viewGroup) {
        Stop entry = listStop.get(position);
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.stop_row, null);
        }

        TextView tvDestination = (TextView) convertView.findViewById(R.id.destination);
        tvDestination.setText("");
        tvDestination.setText(entry.getDestination());

        TextView tvname = (TextView) convertView.findViewById(R.id.name);
        tvname.setText("");
        tvname.setText(entry.getName());
        
        TextView tvRoute = (TextView) convertView.findViewById(R.id.route);
        tvRoute.setText("");
        tvRoute.setText(entry.getRoute());

        return convertView;
    }

    public void onClick(View view) {
        Stop entry = (Stop) view.getTag();
        listStop.remove(entry);
        notifyDataSetChanged();

    }
}




